package com.system.module.business.service.impl;

import com.system.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.page.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.system.module.business.mapper.PatientUserMapper;
import com.system.module.business.domain.PatientUser;
import com.system.module.business.service.IPatientUserService;

import java.util.List;

/**
 * 患者列表业务层处理
 *
 * @author mars
 * @date 2023-06-15
 */
@Slf4j
@Service
public class PatientUserServiceImpl extends ServiceImpl<PatientUserMapper, PatientUser> implements IPatientUserService {

    @Override
    public PatientUser add(PatientUser param) {
        super.save(param);
        return param;
    }

    @Override
    public boolean delete(Integer id) {
        return this.removeById(id);
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        return this.removeByIds(ids);
    }

    @Override
    public boolean update(PatientUser param) {
        return this.updateById(param);
    }

    @Override
    public PatientUser findById(Integer id) {
        return this.getById(id);
    }

    @Override
    public PageInfo<PatientUser> findPageBySpec(PatientUser param) {
        Page<PatientUser> page = new Page<>(param.getPageNum(), param.getPageSize());
        LambdaQueryWrapper<PatientUser> query = this.buildWrapper(param);
        Page<PatientUser> pageRecord = this.page(page, query);
        return PageInfo.build(pageRecord);
    }

    @Override
    public List<PatientUser> getList(PatientUser param) {
        LambdaQueryWrapper<PatientUser> query = this.buildWrapper(param);
        return this.list(query);
    }


    private LambdaQueryWrapper<PatientUser> buildWrapper(PatientUser param) {
        LambdaQueryWrapper<PatientUser> query = new LambdaQueryWrapper<>();
         if (StringUtils.isNotBlank(param.getName())){
               query.like(PatientUser::getName ,param.getName());
        }
        if (param.getGender() != null){
               query.eq(PatientUser::getGender ,param.getGender());
        }
        return query;
    }

}
